<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>switch05</title>
		<style type="text/css">
			.box{
				text-align: center;
			}
			.switch{
				margin: auto;
				width: 50px;
				padding: 10px 20px;
				border-radius: 4px;
				border: 2px solid blueviolet;
				cursor: pointer;
			}
		</style>
	</head>
	<body>
		<div class="box">
			<div class="switch">
				关
			</div>
			<div class="main">
				<img id="img" src="img/pic_bulboff.gif" />
			</div>
		</div>
		<script type="text/javascript">
			var btn = document.querySelector('.switch');
			var img = document.querySelector('#img');
			btn.onclick = function(){
				if(this.innerHTML == '关'){
					img.src = 'img/pic_bulbon.gif';
					this.innerHTML = '开';
					this.style.backgroundColor = 'yellow';
				}else{
					img.src = 'img/pic_bulboff.gif';
					this.innerHTML = '关';
					this.style.backgroundColor = '';
				}
			}
		</script>
	</body>
</html>
